import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'

declare module 'vue-router' {
  interface RouteMeta {
    title: string,
    transition: string
  }
}

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    alias: ['/user-login'],
    meta: { title: '登录页面', transition: 'animate__bounceInLeft' },
    // component: () => import('../views/userIndex.vue')
    component: () => import('@/views/userLogin.vue'),
  },
  {
    path: '/user-index',
    meta: { title: '首页', transition: 'animate__bounceInLeft' },
    component: () => import('@/views/userIndex.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior: (to, from, savedPosition) => {
    // if (savedPosition) {
    //   return savedPosition
    // } else {
    //   return {
    //     top: 0
    //   }
    // }
    return {
      top: 9999999,
      behavior: 'smooth'
    }
    // return new Promise(resolve => {
    //   setTimeout(() => {
    //     console.log(1234567489)
    //     resolve({
    //       top: 99999999
    //     })
    //   }, 2000)
    // })
  }
})

export default router
